home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / chgchar.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.4 KB  |  54 lines

  1. ;void  change_character(strg,search,replace);
  2. ;  unsigned char  *strg,search,replace;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _change_character
  10. _change_character proc near
  11.     push bp            ;
  12.     mov  bp,sp        ;set up stack frame
  13.     push si            ;
  14.     push ds            ;
  15.     cmp  _memory_model,0    ;near or far?
  16.     jle  begin        ;jump if near
  17.     inc  bp            ;else add 2 to BP
  18.     inc  bp            ;
  19. begin:    mov  _error_code,0    ;assume char found
  20.     cmp  _memory_model,2    ;data near or far?
  21.     jb   L0            ;
  22.     lds  si,dword ptr[bp+4] ;SI pts to Strg
  23.     inc  bp            ;add 2 to BP since dword ptr
  24.     inc  bp            ;
  25.     jmp  short L00        ;
  26. L0:    mov  si,[bp+4]        ;near case
  27. L00:    sub  dx,dx        ;flags that a char found
  28.     mov  al,[bp+6]        ;get replacement char
  29.     mov  ah,[bp+8]        ;search character
  30.     cmp  byte ptr[si],0    ;test for null string
  31.     je   L3            ;
  32. L1:    mov  cl,[si]        ;get a character
  33.     cmp  cl,0        ;end of string?
  34.     je   LX            ;
  35.     cmp  cl,ah        ;search char?
  36.     jne  L2            ;jump ahead if not
  37.     mov  [si],al        ;else change char
  38.     inc  dx            ;flag that a char found
  39. L2:    inc  si            ;forward string ptr
  40.     jmp  short L1        ;go do next char
  41. LX:    or   dx,dx        ;test if char found
  42.     jnz  L4            ;jump ahead if so
  43. L3:    inc  _error_code    ;else 1 = char not found
  44. L4:    pop  ds            ;
  45.     pop  si            ;
  46.     pop  bp            ;
  47.     cmp  _memory_model,0    ;quit
  48.     jle  quit        ;
  49.     db   0CBh        ;RET far
  50. quit:    ret            ;RET near
  51. _change_character ENDP
  52. _TEXT    ENDS
  53.     END
  54.